const glob = require("glob").glob;
const cpFile = require("cp-file");

function winToUnixPath(path) {
	return path.replace(/\\/g, "/");
}

function copyFolder(source, target) {
	const userFolder = winToUnixPath(source);
	const targetFolder = winToUnixPath(target);
	const userPaths = glob.sync(`${userFolder}/**`, {
		nodir: true,
		dot: true,
	});
	Promise.all(userPaths.map((pathStr) => {
		if (!pathStr.endsWith('CUSTOM.md')) {
			const outFilePathStr = targetFolder + pathStr.replace(userFolder, "");
			return cpFile(pathStr, outFilePathStr);
		}
	}));
}
console.log(`Start copy custom code...`);
copyFolder('./user', './');
console.log(`Completed copy custom code...`);